<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>调查问卷问题管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			var displayType = '${question.type}';
			   if(displayType =='') displayType ="0";
			 $("input[name='type'][value="+displayType+"]").attr("checked","checked");  
			
		});
		
		
		function clickText(){
			$("#optiondetails").remove();
		}
		function clickoption(){
			$("#optiondetails").remove();
			if($("#optiondetails").length==0){
				
			var html="";
			html+='<div class="control-group"  id="optiondetails">'
			+'<label class="control-label">选项:</label>'
			+'<div class="controls">'
			+'<ol id="option">'
			+'<li><input type="text" name="options" class="required" ></li>'
			  +'</ol>'
			+'<button type="button" class="btn btn-primary" onclick="add();">添加</button>'
			+'</div>'
			+'</div>';
			$("#questionType").after(html);
			}
		}
		
		function add(){
			var html="";
			html+=' <li><input type="text" name="options" class="required" ></li>';
			$("#option").append(html);
			
			$("#inputForm").validate({
				
			})
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/wechat/question/voterList?questionnaireId=${questionnaireId}">竞选人列表</a></li>
		<li class="active"><a>添加竞选人</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="question" action="${ctx}/wechat/question/saveVoter" method="post" class="form-horizontal" enctype="multipart/form-data">
		<form:hidden path="id"/>
		<form:hidden path="user.id"/>
		<form:hidden path="questionnaire.id"/>
		<tags:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">竞选人姓名:</label>
			<div class="controls">
				<form:input path="voterName" htmlEscape="false" maxlength="100" class="required"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">描述:</label>
			<div class="controls">
				<form:textarea id="question" htmlEscape="true"  path="question" rows="4"  class="input-xlarge required"/>
				<tags:ckeditor replace="question" uploadPath="/project/pics" />
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">显示图片上传:</label>
			<div class="controls">
				<c:if test="${question.showPic ne '' }">
					<div class="control"><img src="${ctxUser }/questionnaire/${question.showPic }" style="width:200px;height:300px"/></div>
				</c:if>
				<div class="control">
					<input type="file" name="picFile1" htmlEscape="false"   />          
				</div>
			</div>
		</div>
		
		
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>
